home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / ca29_3.zip / LEARN.SRC < prev    next >
Text File  |  1992-09-21  |  50KB  |  1,811 lines

  1.    SET TTHRU OFF        ; Make first to allow typeahead
  2.    S19 = "Learn   ver 1.0     " ; 20 chars long
  3. ; ----- Learn: Learn mode shell for COM-AND
  4. ;
  5. ;    R.McG; 8/89, Chicago
  6. ; ----------------------------------------------------------------
  7. ; Usages:
  8. ;      S19 -----> Legend line
  9. ;      S18 -----> Load-time drive:subdirectory (for exit)
  10. ;      S17 -----> Load-time download d:subdir (for exit)
  11. ;      S16 -----> Output file name
  12. ;      S12 -----> Text before last line displayed to screen
  13. ;      S11 -----> Last line displayed to screen
  14. ;      S10 -----> Current output buffer
  15. ;
  16. ;      N99 -----> Number of lines on screen
  17. ;      N96 -----> Current receive area cursor
  18. ;      N95 -----> Current receive area cursor
  19. ;      N94 -----> Current Kbd area cursor
  20. ;      N93 -----> Current Kbd area cursor
  21. ;      N92 -----> Saved cursor on entry
  22. ;      N91 -----> Saved cursor on entry
  23. ;      N90 -----> Current output buffer index
  24. ;
  25. ;      FLAG(0) -> ESCAPE has been hit if ON
  26. ;      FLAG(1) -> Off: no printer    on: Printer in use
  27. ;      FLAG(2) -> Off: log not used    on: Log was used
  28. ;      FLAG(8) -> Off: learning,    on: learning suspended
  29. ;      FLAG(9) -> Off: in line mode, on: in character mode
  30. ; -----------------------------------------------------------------------
  31. ;
  32. ;    Initialization
  33. ;
  34.    CURSOR N91,N92        ; Read current cursor
  35.    LEGEND S19            ; Set initial legend
  36.    SUBDIR S18            ; Read current subdir
  37.    DLDIR S17            ; Read current download subdir
  38.    SSIZE N99            ; Get current screen size
  39.    SAVE 0,0,N99-2,79        ; Save original screen
  40.    ON ESCAPE GOSUB ESCAPE    ; Escape action
  41.    SET FLAG(1) OFF        ; Set printer on/off flag
  42.    IF STRCMP "_PRIN" "ON"       ; .. as we only turn printer on
  43.       SET FLAG(1) ON        ; .. during receive portion
  44.       PRINTER OFF        ; Turn printer off unconditionally
  45.       ENDIF
  46. ;
  47. ;    Ask for an output file name
  48. ;
  49. Get_Output:
  50.    S1 = "Enter a file name to be output:"
  51.    GOSUB Ask_File        ; Ask for an output file
  52.    IF NOT SUCCESS EXIT        ; If ESC'd then stop
  53.    S16 = S0            ; Save fname
  54. ;
  55. ;    Test for file existing
  56. ;
  57.    IF ISFILE S16        ; If file exists
  58.       S0 = S16 *" already exists.  Overwrite it? Y/N (cr=no)"
  59.       GOSUB Ask_YN
  60.       IF NOT SUCCESS GOTO Get_Output
  61.       ENDIF
  62. ;
  63. ;    Open the output file, no append
  64. ;
  65.    FOPENO S16 TEXT        ; Open output file
  66.    IF NOT SUCCESS
  67.       S0 = "Error opening output file: "*S16
  68.       GOSUB Error        ; Report
  69.       GOTO Get_output
  70.       ENDIF
  71. ;
  72. ;    Perform other initialization
  73. ;
  74.    GOSUB Initial        ; Save initial settings
  75.    SET CHAT OFF         ; Turn off chat
  76.    GOTO START            ; And continue
  77. ;
  78. ; ----- Subroutine: Escape - Set a flag for mainline loop
  79. ;
  80. Escape:
  81.    SET FLAG(0) ON        ; Flag fact
  82.    RETURN            ; And continue
  83. ;
  84. ;------ Subroutine: Terminate the all LEARN script activity
  85. ;
  86. End_Learn:
  87.    DWINDOW CLEAR        ; Clear display window
  88.    IF FLAG(2) and STRCMP "_LOGG" "ON "
  89.       WRITE "LOG CLOSE!"        ; FInish logging if on and turned on within
  90.       LOG CLOSE
  91.       ENDIF
  92.    WRITE "^Z" 2                 ; Terminate w/EOF
  93.    FCLOSEO            ; Close output file
  94.    SET DLDIR S17        ; Reset DLDIR  to load time
  95.    CHDIR S18            ; Reset default subdir to load time
  96.    RESTORE            ; Restore screen
  97.    LOCATE N91,N92        ; Restore cursor
  98.    IF FLAG(1)            ; Set printer according to current state
  99.       PRINTER ON
  100.    ELSE
  101.       PRINTER OFF
  102.       ENDIF
  103.    RETURN            ; Rtn to caller
  104. ;
  105. ;------ Subroutine: Ask if Exit to be taken
  106. ;
  107. Exit:
  108.    S0 = "Do you wish to terminate LEARN?  Enter Y to terminate."
  109.    GOSUB Ask_YN
  110.    IF SUCCESS            ; IF answer is 'y'
  111.       GOSUB End_Learn        ; Terminate
  112.       EXIT            ; And stop script
  113.       ENDIF
  114.    SET FLAG(0) OFF        ; Clear ESC flag
  115.    RETURN            ; And continue
  116. ;
  117. ; ----- Main-line: Draw the screen, and begin loop
  118. ;
  119. Start:
  120.    N90 = 0            ; Initialize buffer index
  121.    S11 = ""                     ; Init last line received
  122.    S12 = ""                     ; Init next ot last line received
  123.    SET FLAG(0) OFF        ; Init ESC hit flag
  124.    SET FLAG(9) OFF        ; Init to line mode
  125.    SET FLAG(8) OFF        ; Init to not held
  126.    GOSUB Screen         ; Draw screen
  127.    LOCATE 1,1            ; Set cursor
  128.    DWINDOW N99-12,2 N99-12 77    ; Set kbd scrolling region
  129.    GOTO Main
  130. ;
  131. ;    Write a line (in S0, less CRLF) to the output file
  132. ;
  133. Output:
  134.    WRITE S0            ; Write to file
  135.    WRITE "!"                    ; Add a crlf
  136. ;
  137. ;    Display received text, and wait for a keypress
  138. ;
  139. Main:
  140.    LOCATE N93,N94        ; Set kbd cursor
  141.    IF FLAG(0) GOSUB Exit    ; If ESC pressed, ask if to exit
  142.    IF NOT HITKEY        ; If nothig on kbd
  143.       IF RECEIVE GOSUB Receive    ; Allow incoming text to be displayed
  144.       GOTO Main
  145.       ENDIF
  146. ;
  147. ;    We have a keypress pending
  148. ;
  149.    KEYGET S1            ; Read a single key
  150.    LENG S1 N0            ; Compute length of KEYGET
  151.    SWITCH N0
  152.       CASE 1            ; length = 1
  153.      GOTO ASCII
  154.       ENDCASE
  155.       CASE 2            ; length = 2
  156.      GOTO CONTROL
  157.       ENDCASE
  158.       CASE 4            ; length = 4
  159.      GOTO FUNCTION
  160.       ENDCASE
  161.    ENDSWITCH
  162.    GOTO Main            ; And continue
  163. ;
  164. ;    Update the keyboard display
  165. ;
  166. KbdDisp:
  167.    IF GT N90 0
  168.       S0 = S10(0:n90-1)     ; COpy current buffer
  169.       PRESERVE S0        ; Make displayable
  170.       ATSAY N99-12,2 (Default) S0 *"  "
  171.       ENDIF
  172.    N94=N90+2            ; Set new col #
  173.    GOTO Main
  174. ;
  175. ; ----- Subroutine: Handle receipt of text
  176. ;
  177. Receive:
  178.    DWINDOW 1, 0,(N99-14),79    ; Set rcv scrolling region
  179.    IF FLAG(1) PRINTER ON    ; Turn on printer while reading comm
  180.    LOCATE N95,N96        ; Set rcv cursor
  181.    S12 = S11            ; Save previous line read
  182.    RGET S11 80 1        ; Read new text, max wait 1 sec
  183.    CURSOR N95,N96        ; Read new rcv area cursor
  184.    IF FLAG(1) PRINTER OFF    ; Turn off printer now
  185.    DWINDOW N99-12,2 N99-12,77    ; Set kbd scrolling region
  186.    RETURN
  187. ;
  188. ;    ASCII char entered: length in N0 is 1
  189. ;
  190. ASCII:
  191.    IF FLAG(8)            ; If learn held
  192.       PRESERVE S1        ; ..
  193.       TRANSMIT S1        ; Send the char
  194.       GOTO Main         ; .. and no more
  195.       ENDIF
  196.    ;
  197.    ;    Catch buffer overflow (limit kbd buffer to 60 chars)
  198.    ;
  199.    IF GT (N90+2) 60
  200.       SOUND 100,100
  201.       GOTO Main
  202.       ENDIF
  203.    ;
  204.    ;    Buffer the char (preserving for TRANSMIT)
  205.    ;
  206.    S10(N90:N90) = S1        ; Buffer keystroke
  207.    INC N90
  208.    IF STRCMP S1 "!" or STRCMP S1 "^"
  209.       S10(N90:N90) = S1     ; DOuble special chars to PRESERVE for TRANSMIT
  210.       INC N90
  211.       ENDIF
  212.    ;
  213.    ;    If CHAR mode, send immediate
  214.    ;
  215.    IF FLAG(9) GOTO Transmit    ; If char mode transmit immediately
  216.    GOTO KbdDisp         ; Update kbd display
  217. ;
  218. ;    Handle control chars: length in N0 is 2
  219. ;
  220. Control:
  221.    S0 = "0x"*S1                 ; Make hex form of #
  222.    N0 = S0            ; If ctl char (e.g. 0d for c/r)
  223.    N0 = N0+64            ; Convert to ASCII @,A,B,...
  224.    S0 = "^"                     ; Store delimiter
  225.    ITOC N0 S0(1:1)        ; Store char being ctl'd
  226.    ;
  227.    ;    Simply xmit if LEARN HELD
  228.    ;
  229.    IF FLAG(8)            ; If learn held
  230.       TRANSMIT S0        ; Send the char
  231.       GOTO Main         ; .. and no more
  232.       ENDIF
  233.    ;
  234.    ;    Catch special control chars
  235.    ;
  236.    IF (NOT FLAG(9)) and STRCMP S1 "08" ; Catch backspace here
  237.       GOTO Backspace               ; .. in line mode
  238.       ENDIF
  239.    IF STRCMP S1 "0D"            ; Catch c/rs
  240.       GOTO RETURN        ; .. in either line or char mode
  241.       ENDIF
  242.    IF GT (N90+2) 60        ; Handle buffer overflow here
  243.       SOUND 100,100
  244.       GOTO Main
  245.       ENDIF
  246.    ;
  247.    ;    Buffer the remainder as "^" chars
  248.    ;
  249.    S10(N90:N90+1) = S0(0:1)    ; Store delimiter
  250.    N90 = N90+2
  251.    IF FLAG(9) GOTO Transmit    ; If char mode transmit directly
  252.    GOTO KbdDisp         ; Update kbd display
  253. ;
  254. ;    Backspace entered
  255. ;
  256. Backspace:
  257.    IF ZERO N90
  258.       GOTO KbdDisp
  259.       ENDIF
  260.    DEC N90
  261.    IF STRCMP S10(N90-1:N90-1) "^" or STRCMP S10(N90-1:N90) "!!"
  262.       DEC N90
  263.       ENDIF
  264.    GOTO KbdDisp         ; Update kbd display
  265. ;
  266. ;    Carriage return entered
  267. ;
  268. Return:
  269.    IF NOT ZERO N90
  270.       S10 = S10(0:N90-1)*"!"
  271.    ELSE
  272.       S10 = "!"
  273.       ENDIF
  274.    N90 = N90+1
  275. ;
  276. ;    Execute the current buffer
  277. ;
  278. Transmit:
  279.    GOSUB Waitfor        ; Emit a WAITFOR
  280.    ;
  281.    ;    Now, emit a TRANSMIT statement
  282.    ;
  283.    WRITE "TRANSMIT `""          ; Write TRANSMIT statement
  284.    IF STRCMP S10(N90-1:N90-1) "!!"
  285.       WRITE S10 N90-1        ; Write string to be xmitted less final c/r
  286.